﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Perform
{
    public partial class frmInventoryAdd : Form
    {
        public frmInventoryAdd()
        {
            InitializeComponent();
        }

        private void btnupdate_Click(object sender, EventArgs e)
        {
            this.Hide();
        }

        private void frmInventoryAdd_Load(object sender, EventArgs e)
        {
            tbsum.Text = "0";
            tbout.Text = "0";
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string fid = tbfid.Text.Trim();
            string fname = tbname.Text.Trim();
            string Ssum = tbsum.Text.Trim();
            string fout = tbout.Text.Trim();
            int iout = Convert.ToInt32(tbout.Text.Trim());
            int sum = Convert.ToInt32(tbsum.Text.Trim());
            tbresidue.Text = (sum - iout).ToString();
            try
            {
                string sql = string.Format("insert into inventory values('{0}','{1}',{2},{3},{4})", tbname.Text.Trim(), tbfid.Text.Trim(), sum, iout, tbresidue.Text.Trim());
                if(fid == "" || fname == "" || Ssum == "" || fout == "")
                {
                    MessageBox.Show("请输入完整的信息！", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                else if (Dal.DataHelper.sqlExecuteNonQuery(sql) > 0)
                {
                    MessageBox.Show("添加仓库信息成功！", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                else
                {
                    MessageBox.Show("添加仓库信息失败！", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
            }
            catch (Exception ex) { MessageBox.Show(ex.Message, "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); }
        }
    }
}
